<html>
<head>

      <script type="text/javascript">
      function calcBondPx(form) {
      var parseCvt = 1000*60*60*24;
      var princ = parseInt(form.principal.value);
      var setDt = parseInt(Date.parse(form.settleDate.value) / parseCvt);
      var matDt = parseInt(Date.parse(form.maturityDate.value) / parseCvt);
      var cpn = parseFloat(form.coupon.value);
      var yld = parseFloat(form.yld.value);
      if (cpn > 1) {
      cpn = cpn /100}
      if (yld > 1) {
      yld = yld /100}
      var yearFrac = (matDt-setDt)/365;

      var cfVal = cpn * (1 - (1 / Math.pow((1+yld),yearFrac))) / yld;
      var zVal = 1 / (Math.pow((1+yld),yearFrac));
      var tmpBondPx = princ * (cfVal + zVal);
      alert("matDt: "+matDt+ " setDt: "+setDt+ " yF: "+yearFrac+ " cpn:" +cpn+ " yld: " +yld+ " princ: " +princ+ " cfVal: " + cfVal + " zVal: " + zVal);
      document.getElementById('content_div').innerHTML = "BondPX(clean): " + String(tmpBondPx);
      }
      </script>



<head>
<body>
<FORM NAME="mysbc" ACTION="" METHOD="GET">
      <div style="font-family:verdana;font-size:14px">
      <u>Thiru's Simple Bond Calculator</u>:
      </div>
      <div style="font-family:verdana;color:green;font-size:12px">

      Principal: <INPUT TYPE="text" Size="8" NAME="principal" VALUE=""><br />
      Settle Date: <INPUT TYPE="text" Size="12" maxLength="10" title="Format : mm/dd/yyyy" NAME="settleDate" VALUE=""><br />
      Maturity Date: <INPUT TYPE="text" Size="12" maxLength="10" title="Format : mm/dd/yyyy" NAME="maturityDate" VALUE=""><br />
      Coupon: <INPUT TYPE="text" Size="6" NAME="coupon" VALUE=""><br />
      Yield: <INPUT TYPE="text" Size="6" NAME="yld" VALUE="">
      </div>
      <INPUT TYPE="button" style=height:"20" NAME="cbutton" VALUE="Calc Bond Cln Px" onClick="calcBondPx(this.form)">
      </FORM>

      <div id="content_div" style="font-family:verdana;color:blue;font-size:12px"></div>
</body>
</html>